package xiaohu.day2.HJ25;

import java.util.*;
import java.util.stream.Collectors;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {

    static List<Integer> l = new ArrayList();

    static List<Integer> r = new ArrayList();

    static List<Integer> ans = new ArrayList();

    static class Item {
        int dx;
        int val;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            for (int i = 0; i < n; ++ i) l.add(in.nextInt());
            n = in.nextInt();
            for (int i = 0; i < n; ++ i) r.add(in.nextInt());
            r = r.stream().distinct().sorted().collect(Collectors.toList());//去重、排序

            for (int a : r) {
                List<Item> t = new ArrayList();
                for (int i = 0; i < l.size(); ++ i) {
                    String str = l.get(i) + "";
                    if (str.contains(a + "")) {
                        Item it = new Item();
                        it.dx = i;
                        it.val = l.get(i);
                        t.add(it);
                    }
                }
                if (t.size() > 0) {
                    ans.add(a);
                    ans.add(t.size());
                    for (Item it : t) {
                        ans.add(it.dx);
                        ans.add(it.val);
                    }
                }
            }

            System.out.print(ans.size() + " ");
            for (int a : ans) System.out.print(a + " ");
        }
    }
}
